function loadImg(src){
  return new Promise(
    (resolve, reject) => {
      const img = document.createElement('img')
      img.onload = () => {
        resolve(img)
      }
      img.onerror = () =>{
        const err = new Error(`图片加载失败 ${src}`)
        reject(err)
      }
      img.src = src
    }
  )
}

// img 地址
const url = "https://user-images.githubusercontent.com/799578/50462941-8075fe80-09c3-11e9-89e7-af0cb7991406.png"

// loadImg(url).then(img => {
//   console.log(`宽度为: ${img.width}`)
//   return img
// }).then(img => {
//   console.log(`高度为: ${img.height}`)
// }).catch(ex => console.error(ex))

const url2 = "https://gitee.com/static/images/logo-en.svg"
loadImg(url).then(img => {
  console.log(img.width)
  return img
}).then(img => {
  console.log(img.height)
  return loadImg(url2) // promise 实例
}).then(img2 => {
  console.log(img2.width)
  return img2
}).then(img2 => {
  console.log(img2.height)
}).catch(ex => console.error(ex))